package zhj.test.ballmove;

import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

public class Ball {
	//current x pos
	private double x=0;
	//current y pos
	private double y=0;
	private double dx =1; 
	private double dy =1;
	private static final int XSIZE =15;
	private static final int YSIZE =15;
	public double getX() {
		return x;
	}
	public void setX(double x) {
		this.x = x;
	}
	public double getY() {
		return y;
	}
	public void setY(double y) {
		this.y = y;
	}
	public double getDx() {
		return dx;
	}
	public void setDx(double dx) {
		this.dx = dx;
	}
	public double getDy() {
		return dy;
	}
	public void setDy(double dy) {
		this.dy = dy;
	} 
	
	public void move(Rectangle2D bounds)
	{
		if( x == bounds.getMinX())
		{
			setDx(1);
			x += dx;
		} 
		else if( x == bounds.getMaxX())
		{
			x= bounds.getMaxX() - 1; 
			setDx(-1);
		}
		else if(x < bounds.getMaxX() && x > bounds.getMinX())
		{
			x  += dx; 
		}
		
		
		if( y == bounds.getMinY())
		{
			setDy(1);
			y += dy;
		}
		else if( y == bounds.getMaxY())
		{
			y = bounds.getMaxY() - 1; 
			setDy(-1);
		}
		else  if(y < bounds.getMaxY() && y > bounds.getMinY())
		{
			y  += dy; 
		}
		
		System.out.print(x);
		System.out.print(" ");
		System.out.print(y);
		System.out.println("");
	}
	
	public Ellipse2D getShape()
	{
		return new Ellipse2D.Double(x,y,XSIZE,YSIZE);
	}
	
}
